#*****************************************************************
#  name         : nginx
#  remark       : nginx latest
#  tag          : latest
#  level        : service
#  author       : mason
#  build shell  : docker build -t 10.100.135.125:5000/nginx:latest .
#  run shell    : docker run -d -P --name nginx.7.0 10.100.135.125:5000/nginx:latest .
#  push shell   : docker push 10.100.135.125:5000/nginx:latest
#  pull shell   : docker pull 10.100.135.125:5000/nginx:latest
#*****************************************************************

FROM 10.100.135.125:5000/centos:7.0

MAINTAINER "mason" <masl@mail.open.com.cn>

LABEL company="OPEN"

RUN \
    mkdir /data/server/nginx && \
    mkdir /data/server/nginx/src && \
    mkdir /data/log/nginx && \
    cd /data/server/nginx && \
    yum install -y vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* nasm* gcc gcc* gcc-c++ ntp make imake cmake automake autoconf zlib zlib-devel glibc glibc-devel glib2 libxml glib2-devel libxml2 libxml2-devel bzip2 bzip2-devel libXpm libXpm-devel libidn libidn-devel libtool libtool-ltdl-devel* libmcrypt libmcrypt-devel libevent-devel libmcrypt* curl curl-devel perl perl-Net-SSLeay pcre pcre-devel ncurses ncurses-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers krb5 krb5-devel e2fsprogs e2fsprogs-devel libjpeg libpng libjpeg-devel libjpeg-6b libjpeg-devel-6b libpng-devel libtiff-devel freetype freetype-devel fontconfig-devel gd gd-devel kernel screen sysstat flex bison nss_ldap pam-devel compat-libstdc++-33 gd-devel pcre-devel libcurl-devel && \
    yum clean all && \
    wget -P /data/server/nginx/src http://f.open.com.cn/S/shell/nginx/nginx-1.9.12.tar.gz && \
    tar -zxvf /data/server/nginx/src/nginx-1.9.12.tar.gz -C /data/server/nginx/src && \
    rm -f /data/server/nginx/src/nginx-1.9.12.tar.gz && \
    groupadd nginxgroup && \
    useradd -s /sbin/nologin -g nginxgroup nginxuser && \
    cd /data/server/nginx/src/nginx-1.9.12
#fguo unzip ngx_image_thumb-master.zip

WORKDIR /data/server/nginx/src/nginx-1.9.12

RUN ./configure --prefix=/data/server/nginx/nginx-1.9.12 \
--user=nginxuser \
--group=nginxgroup \
--with-mail \
--with-mail_ssl_module \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_dav_module \
--with-http_sub_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre \
--with-http_image_filter_module
#fguo --add-module=./nginx-image-master

#--with-http_spdy_module \

RUN \
    make  && \
    make install && \
    rm -rf /data/server/nginx/src && \
    ln -s /data/server/nginx/nginx-1.9.12 /data/server/nginx/default && \
    mkdir /data/server/nginx/default/vhost && \
    mkdir /data/server/nginx/default/www

ENV NGINX_HOME=/data/server/nginx/default
ENV PATH=$PATH:$NGINX_HOME/sbin
ENV RESTREAM_URL http://localhost:8080

WORKDIR /data/server/nginx/default

COPY nginx /etc/init.d/
RUN \
    chmod 777 /data/server/nginx/default/sbin/* && \
    echo "NGINX_HOME=/data/server/nginx/default" >> /etc/profile && \
    echo "PATH=$PATH:$NGINX_HOME/sbin" >> /etc/profile && \
    chmod 777 /etc/init.d/nginx

COPY ./files/etc/nginx.conf $NGINX_HOME/conf/
COPY ./files/etc/default.conf /data/server/nginx/default/vhost/
COPY ./files/www/* /data/server/nginx/default/www/
COPY ./files/shell/bootstart.sh /data/shell/


COPY ./files/shell/build_run.sh /data/shell/
COPY ./files/shell/docker_run.sh /data/shell/

RUN chmod 777 /data/shell/build_run.sh && \
    chmod 777 /data/shell/docker_run.sh && \
    sh /data/shell/build_run.sh

EXPOSE 80 443
ENTRYPOINT /data/shell/docker_run.sh && /bin/bash
